package com.example.homework;

import org.junit.jupiter.api.Test;

public class Homework01 {
    public static void main(String[] args) {
        User user1 = new User(1, 20, "tom");
        User user2 = new User(2, 21, "jack");
        User user3 = new User(3, 22, "john");
        User user4 = new User(4, 23, "lily");
        User user5 = new User(5, 24, "cathy");

        //添加
        DAO<User> userDAO = new DAO<>();
        userDAO.save(String.valueOf(user1.getId()), user1);
        userDAO.save(String.valueOf(user2.getId()), user2);
        userDAO.save(String.valueOf(user3.getId()), user3);
        userDAO.save(String.valueOf(user4.getId()), user4);
        userDAO.save(String.valueOf(user5.getId()), user5);

        System.out.println("id查询");
        System.out.println(userDAO.get("2"));

        System.out.println("修改操作");
        userDAO.update("2", new User(2, 20, "jackie"));
        System.out.println(userDAO.get("2"));

        System.out.println("list遍历");
        System.out.println(userDAO.list());
        for (User user : userDAO.list()) {
            System.out.println(user);
        }

        System.out.println("delete删除操作");
        userDAO.delete("2");
        for (User user : userDAO.list()) {
            System.out.println(user);
        }
    }

    @Test
    public void testList(){
        User user1 = new User(1, 20, "tom");
        User user2 = new User(2, 21, "jack");
        User user3 = new User(3, 22, "john");
        User user4 = new User(4, 23, "lily");
        User user5 = new User(5, 24, "cathy");

        //添加
        DAO<User> userDAO = new DAO<>();
        userDAO.save(String.valueOf(user1.getId()), user1);
        userDAO.save(String.valueOf(user2.getId()), user2);
        userDAO.save(String.valueOf(user3.getId()), user3);
        userDAO.save(String.valueOf(user4.getId()), user4);
        userDAO.save(String.valueOf(user5.getId()), user5);

        System.out.println("id查询");
        System.out.println(userDAO.get("2"));

        System.out.println("修改操作");
        userDAO.update("2", new User(2, 20, "jackie"));
        System.out.println(userDAO.get("2"));

        System.out.println("list遍历");
        System.out.println(userDAO.list());
        for (User user : userDAO.list()) {
            System.out.println(user);
        }

        System.out.println("delete删除操作");
        userDAO.delete("2");
        for (User user : userDAO.list()) {
            System.out.println(user);
        }
    }
}
